import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { defHttp } from '/@/utils/http/axios';
import { UploadTypeEnum } from '/@/components/Form/src/jeecg/components/JUpload';

import { render, formattingMin, formattingDay, formatTimestamp, mainTravelStats } from '/@/utils/common/renderUtils';
//列表数据
export const columns : BasicColumn[] = [
	/* 	{
			title: '类型',
			align: "center",
			dataIndex: 'type'
		}, */
	{
		title: '报名截止日期',
		align: "center",
		dataIndex: 'expiredate',
		customRender: ({ text }) => {
			return formatTimestamp(text)
		}
	},
	{
		title: '创建时间',
		align: "center",
		dataIndex: 'createtime',
		customRender: ({ text }) => {
			return formattingMin(text)
		}
	},
	{
		title: '创建状态',
		align: "center",
		dataIndex: 'stats',
		customRender: ({ text }) => {
			return mainTravelStats(text)

		}
	},
	{
		title: '调度状态',
		align: "center",
		dataIndex: 'dispatchstats',
		customRender: ({ text }) => {
			if (text == 'Audit') {
				return '待调度'
			} else if (text == 'Finished') {
				return '调度完成'
			} else if (text == 'Cancel') {
				return '取消'
			}
		}
	},
	{
		title: '行程标题',
		align: "center",
		dataIndex: 'traveltitle'
	},
	{
		title: '创建用户',
		align: "center",
		dataIndex: 'createuserid_dictText',
		customRender: ({ text }) => {
			if (!text) {
				return '后台创建'
			}
		}
	},
	/* 	{
			title: '游玩景点',
			align: "center",
			dataIndex: 'pretravellineid',
			customRender:({text})=>{
				
			}
		}, */
	/* {
		title: '租户ID',
		align: "center",
		dataIndex: 'tenantid'
	}, */
	{
		title: '出发日期',
		align: "center",
		dataIndex: 'startdate',
		customRender: ({ text }) => {
			let o = formatTimestamp(text);
			return o.split(" ")[0]
		}
	},
	{
		title: '游玩天数',
		align: "center",
		dataIndex: 'travelDays'
	},
	{
		title: '最大人数',
		align: "center",
		dataIndex: 'maxUserNum'
	},
	{
		title: '合同ID',
		align: "center",
		dataIndex: 'contractid'
	},
	{
		title: '保险ID',
		align: "center",
		dataIndex: 'insuranceid'
	},


	{
		title: '备注',
		align: "center",
		dataIndex: 'remark'
	},
	{
		title: '成团人数',
		align: "center",
		dataIndex: 'extInfor',
		customRender: ({ text }) => {
			return JSON.parse(text).groupUserSize
		}

	},
	/* {
		title: '预选车辆',
		align: "center",
		dataIndex: 'pretravelcarlist'
	}, */
	/* 	{
			title: '旅游路线，json',
			align: "center",
			dataIndex: 'travellineremark'
		}, */
];
//查询数据
export const searchFormSchema : FormSchema[] = [

	/* 	{
		   label: '大团',
		   field: 'maxGroupId',
		   component: 'JSearchSelect',
		   componentProps: {
			   dict: 'BS_TravelGroup_TraveListGroup,titleGroup.mainTitle,id',
			   async:true,
			   pageSize:10
		   },
	   }, */

	{
		label: '标题',
		field: 'traveltitle',
		component: 'Input',
	},
	{
		label: '游玩天数',
		field: 'traveldays',
		component: 'InputNumber',
	},
	{
		label: '行程状态',
		field: 'stats',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: 'stroke_state'
		},

	},
];
//表单数据
export const formSchema : FormSchema[] = [
	/* 	{
			label: '类型',
			field: 'type',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入类型!' },
				];
			},
		}, */
	{
		label: '行程状态',
		field: 'stats',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: 'stroke_state'
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入创建状态!' },
			];
		},
	},
	/* 	{
			label: '调度状态',
			field: 'dispatchstats',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入调度状态!' },
				];
			},
		}, */
	/* {
		label: '创建用户ID',
		field: 'createuserid',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入创建用户ID!' },
			];
		},
	}, */
	{
		label: '旅游天数',
		field: 'traveldays',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入旅游天数!' },
			];
		},
		dynamicDisabled: true
	},
	/* 	{
			label: '预设路线ID',
			field: 'pretravellineid',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入预设路线ID!' },
				];
			},
		}, */

	/* 	{
			label: '租户ID',
			field: 'tenantid',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入租户ID!' },
				];
			},
		}, */
	{
		label: '出发日期',
		field: 'startdateStr',
		component: 'DatePicker',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择出发日期!' },
			];
		},
	},

	{
		label: '最大人数',
		field: 'maxusernum',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入最大人数!' },
			];
		},
	},
	{
		label: '合同ID',
		field: 'contractid',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入合同ID!' },
			];
		},
	},
	{
		label: '保险ID',
		field: 'insuranceid',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入保险ID!' },
			];
		},
	},
	{
		label: '增值服务类别',
		field: 'keyCode',
		component: 'JDictSelectTag',
		componentProps: {
			dictCode: "pdt_category"
		},
		required: true,
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择绑定产品类别。!' },
			];
		},

	},
	{
		label: '报名截止时间',
		field: 'expiredateStr',
		component: 'DatePicker',
		componentProps: {
			showTime: true,
			valueFormat: 'YYYY-MM-DD HH:mm:ss'
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入报名截止日期!' },
			];
		},
	},

	/* {
		label: '行程标题',
		field: 'traveltitle',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入旅游标题!' },
			];
		},
	}, */
	{
		label: '备注',
		field: 'remark',
		component: 'InputTextArea',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入备注!' },
			];
		},
	},
	/* 	{
			label: '其他信息',
			field: 'extinfor',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入其他信息!' },
				];
			},
		}, */
	/* 	{
			label: '预选车辆',
			field: 'pretravelcarlist',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入预选车辆!' },
				];
			},
		}, 
		{
			label: '旅游路线',
			field: 'travellineremark',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入旅游路线!' },
				];
			},
		},*/
	// TODO 主键隐藏字段，目前写死为ID
	{
		label: '',
		field: 'id',
		component: 'Input',
		show: false
	},
];

//表单数据--拼车发起
export const formSchemaSelf : FormSchema[] = [
	/* 	{
			label: '类型',
			field: 'type',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入类型!' },
				];
			},
		}, */

	{
		label: '行程标题',
		field: 'traveltitle',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入行程标题!' },
			];
		},
	},
	{
		label: '行程标签',
		field: 'tags',
		component: 'Input',
		helpMessage: '逗号分割',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入行程标题!' },
			];
		},
	},
	{
		label: '上架',
		field: 'sjSelect',
		component: 'JDictSelectTag',
		componentProps: {
			options: [
				{ label: '立即上架', value: '1' },
				{ label: '定时上架', value: '0' },
			]
		},
	},

	{
		label: '上架时间',
		field: 'startdateSj',
		component: 'DatePicker',
		componentProps: {
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			showTime: true
		},
		show: ({ values }) => {
			return values.sjSelect == 0
		}
	},
	{
		label: '下架',
		field: 'xjSelect',
		component: 'JDictSelectTag',
		componentProps: {
			options: [
				{ label: '手动下架', value: '1' },
				{ label: '定时下架', value: '0' },
			]
		},
	},
	{
		label: '下架时间',
		field: 'enddateStr',
		component: 'DatePicker',
		componentProps: {
			valueFormat: 'YYYY-MM-DD HH:mm:ss',
			showTime: true
		},
		show: ({ values }) => {
			return values.xjSelect == 0
		}
	},
	/* 	{
			label: '行程状态',
			field: 'stats',
			component: 'JDictSelectTag',
			componentProps: {
				dictCode: 'stroke_state'
			},
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请选择行程状态!' },
				];
			},
		}, */
	{
		label: '出发城市',
		field: 'cityId',
		component: 'ApiSelect',
		/* 	componentProps: {
				dictCode: 'sys_category,name,city_id,pid="1760922454642933761"'
			}, */
		componentProps: ({ formActionType, formModel }) => {

			return {
				//multiple: 多选；不填写为单选
				mode: '',
				//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
				api: () => defHttp.get({ url: '/coupleUser/getCitysByTenantId' }),
				//数值转成String
				numberToString: false,
				//标题字段
				labelField: 'name',
				//值字段
				valueField: 'id',
				//请求参数
				params: {
					carpoolBus: formModel.carpoolBus
				},
				//返回结果字段
				resultField: 'records'
			}

		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择出发城市。!' },
			];
		},
		/* dynamicDisabled: ({ values }) => {
			return values.isUpdate == true
		}, */
	},
	{
		label: '目的地景点',
		field: 'destination',
		component: 'JSearchSelect',
		componentProps: {
			dict: 'BS_Scenic,title,id',
			pageSize: 10,
			async: true
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择目的地景点。!' },
			];
		},
		/* dynamicDisabled: ({ values }) => {
			return values.isUpdate == true
		}, */
	},
	/* 	{
			label: '调度状态',
			field: 'dispatchstats',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入调度状态!' },
				];
			},
		}, */
	/* 	{
			label: '增值服务类别',
			field: 'keyCode',
			component: 'JDictSelectTag',
			componentProps: {
				dictCode: "pdt_category"
			},
			required: true,
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请选择绑定产品类别。!' },
				];
			},
	
		}, */
/* 	{
		label: '增值服务产品',
		field: 'pdtIds',
		component: 'JSelectMultiple',
		componentProps: {
			dictCode: "couple_shop_pdt,title,id"
		},
		required: true,
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择绑定产品!' },
			];
		},
	}, */
	{
		label: '创建用户',
		field: 'createuserid',
		component: 'JSearchSelect',
		componentProps: {
			dict: 'BS_UserLayout_UserInfor,phone,id',
			pageSize: 10
		},
		/* 	dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入创建用户ID!' },
				];
			}, */
	},
	{
		label: '发起人说',
		field: 'fqrContent',
		component: 'InputTextArea',
		/* dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入发起人说!' },
			];
		}, */
	},
	{
		label: '发起人图片',
		field: 'fqrImages',
		component: 'JUpload',
		helpMessage: '最多上传20张图片',
		componentProps: {
			fileType: UploadTypeEnum.image,
			maxCount: 20,
		},
		/* 	dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入发起人说!' },
				];
			}, */
	},
	{
		label: '游玩天数',
		field: 'travelDays',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入游玩天数!' },
			];
		},
		//	dynamicDisabled: true
	},
	{
		label: '预设路线',
		field: 'preTravelLineId',
		component: 'ApiSelect',
		required: true,
		componentProps: ({ formActionType, formModel }) => {

			if (formModel.cityId && formModel.travelDays && formModel.destination) {
				return {
					//multiple: 多选；不填写为单选
					mode: '',
					//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
					api: () => defHttp.get({ url: '/journey/bsTravelgroupTravelistgroup/getTravelLinesByCityId?pageSize=100&cityId=' + formModel.cityId + '&days=' + formModel.travelDays + '&destination=' + formModel.destination }),
					//数值转成String
					numberToString: false,
					//标题字段
					labelField: 'prelinename',
					//值字段
					valueField: 'id',
					//请求参数
					params: {
						carpoolBus: formModel.carpoolBus
					},
					//返回结果字段
					resultField: 'records',
					onChange: async (e : any, record : any) => {
						console.log('----')
						let o = await defHttp.get({ url: '/journey/bsTravelgroupTravelistgroup/getMsgByPreline?preId=' + e })
						console.log(o)
						//这里将增值服务产品也放上来
						

						//formModel.pdtIds = o.pdtIds
						formModel.descriptionOfFees = o.descriptionOfFees
						formModel.itineraryHighlights = o.itineraryHighlights

					}
				}
			}

		},
		/* 		componentProps: ({ formActionType, formModel }) => {
					if (formModel.cityIds && formModel.jDays && formModel.destination) {
						return {
							//multiple: 多选；不填写为单选
							mode: '',
							//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
							api: () => defHttp.get({ url: '/journey/bsTravelgroupTravelistgroup/getTravelLinesByCityId?pageSize=100&cityId=' + formModel.cityIds + '&days=' + formModel.jDays + '&destination=' + formModel.destination }),
							//数值转成String
							numberToString: false,
							//标题字段
							labelField: 'prelinename',
							//值字段
							valueField: 'id',
							//请求参数
							params: {
								carpoolBus: formModel.carpoolBus
							},
							//返回结果字段
							resultField: 'records',
							onChange: async (e : any, record : any) => {
								console.log('----')
								let o = await defHttp.get({ url: '/journey/bsTravelgroupTravelistgroup/getMsgByPreline?preId=' + e })
								console.log(o.descriptionOfFees)
		
								formModel.descriptionOfFees = o.descriptionOfFees
								formModel.itineraryHighlights = o.itineraryHighlights
		
							}
						}
					}
		
				}, */

		/* 	colProps:{
				span:12
			}, */
		dynamicDisabled: ({ values }) => {
			return values.isUpdate == true
		},
	},
	/* 	{
			label: '租户ID',
			field: 'tenantid',
			component: 'Input',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入租户ID!' },
				];
			},
		}, */
	{
		label: '出发日期',
		field: 'startdateStr',
		component: 'DatePicker',
		componentProps: {
			showTime: false,
			valueFormat: 'YYYY-MM-DD'
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请选择出发日期!' },
			];
		},
	},
	{
		label: '建议出行时间段',
		field: 'suggestedTime',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入线路建议出行时间段!' },
			];
		},
	},
	{
		label: '满员人数',
		field: 'maxUserNum',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入最大人数!' },
			];
		},
	},
	{
		label: '成团人数',
		field: 'groupUserSize',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入成团人数！' },
			];
		},
	},
	{
		label: '虚拟报名数',
		field: 'virtualUserNum',
		component: 'InputNumber',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入虚拟报名数!' },
			];
		},
	},
	{
		label: '合同ID',
		field: 'contractid',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入合同ID!' },
			];
		},
	},
	{
		label: '保险ID',
		field: 'insuranceid',
		component: 'Input',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入保险ID!' },
			];
		},
	},
	{
		label: '报名截止时间',
		field: 'expiredateStr',
		component: 'DatePicker',
		componentProps: {
			showTime: true,
			valueFormat: 'YYYY-MM-DD HH:mm:ss'
		},
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入报名截止日期!' },
			];
		},
	},

	{
		label: '预选车辆',
		field: 'pretravelcarlist1',
		component: 'ApiSelect',
		required: true,
		componentProps: ({ formActionType, formModel }) => {
			if (formModel.travelDays) {
				return {
					//multiple: 多选；不填写为单选
					mode: 'multiple',
					//请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
					api: () => defHttp.get({ url: '/scenic/bsPretravelcarprice/list?daynum=' + formModel.travelDays }),
					//数值转成String
					numberToString: false,
					//标题字段
					labelField: 'leveltitle',
					//值字段
					valueField: 'id',
					//请求参数
					params: {
						carpoolBus: formModel.carpoolBus
					},
					//返回结果字段
					resultField: 'records'
				}
			}

		},
	},
	{
		label: '备注',
		field: 'remark',
		component: 'InputTextArea',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入备注!' },
			];
		},
		colProps: {
			span: 24,
		},
	},
	/* 	{
			label: '其他信息',
			field: 'extinfor',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入其他信息!' },
				];
			},
		}, */
	/* 	{
			label: '预选车辆',
			field: 'pretravelcarlist',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入预选车辆!' },
				];
			},
		}, 
		{
			label: '旅游路线',
			field: 'travellineremark',
			component: 'InputTextArea',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入旅游路线!' },
				];
			},
		},*/
	/* 	{
			label: '行程亮点',
			field: 'itineraryHighlights',
			component: 'JEditor',
			dynamicRules: ({ model, schema }) => {
				return [
					{ required: true, message: '请输入行程简介!' },
				];
			},
			colProps: {
				span: 24,
			},
		}, */
	{
		label: '费用说明',
		field: 'descriptionOfFees',
		component: 'JEditor',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入行程简介!' },
			];
		},
		colProps: {
			span: 24,
		},
	},
	{
		label: '退改规则说明',
		field: 'retrofitRule',
		component: 'JEditor',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入行程简介!' },
			];
		},
		colProps: {
			span: 24,
		},
	},
	{
		label: '行前必看',
		field: 'mustSee',
		component: 'JEditor',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入行程简介!' },
			];
		},
		colProps: {
			span: 24,
		},
	},
	{
		label: '行程简介',
		field: 'msg',
		component: 'JEditor',
		dynamicRules: ({ model, schema }) => {
			return [
				{ required: true, message: '请输入旅游路线!' },
			];
		},
		colProps: {
			span: 24,
		},
	},

	// TODO 主键隐藏字段，目前写死为ID
	{
		label: '',
		field: 'id',
		component: 'Input',
		show: false
	},
];

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData) : FormSchema[] {
	// 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
	return formSchema;
}